package com.haohao.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.IdUtil;
import com.haohao.common.annotation.Anonymous;
import com.haohao.system.domain.SysOrders;
import com.haohao.system.service.ISysAppliancesService;
import com.haohao.system.service.ISysOrdersService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haohao.common.annotation.Log;
import com.haohao.common.core.controller.BaseController;
import com.haohao.common.core.domain.AjaxResult;
import com.haohao.common.enums.BusinessType;
import com.haohao.system.domain.SysLogistics;
import com.haohao.system.service.ISysLogisticsService;
import com.haohao.common.utils.poi.ExcelUtil;
import com.haohao.common.core.page.TableDataInfo;

/**
 * 物流配送Controller
 *
 * @author haohao
 * @date 2024-04-12
 */
@RestController
@RequestMapping("/system/logistics")
public class SysLogisticsController extends BaseController
{
    @Autowired
    private ISysLogisticsService sysLogisticsService;
    @Autowired
    private ISysOrdersService sysOrdersService;
    @Autowired
    private ISysAppliancesService sysAppliancesService;
    /**
     * 查询物流配送列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(SysLogistics sysLogistics)
    {
        startPage();
        List<SysLogistics> list = sysLogisticsService.selectSysLogisticsList(sysLogistics);
        return getDataTable(list);
    }



    /**
     * 获取物流配送详细信息
     */
    @Anonymous

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysLogisticsService.selectSysLogisticsById(id));
    }

    /**
     * 新增物流配送
     */
    @Anonymous
    @Log(title = "物流配送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLogistics sysLogistics)
    {
        sysLogistics.setUid(getUserId());
        SysOrders sysOrders = sysOrdersService.selectSysOrdersById(sysLogistics.getTid());
        if (sysOrders!=null){
            sysLogistics.setName(sysOrders.getName());
            sysLogistics.setPic(sysOrders.getPic());
        }
        sysLogistics.setCreateBy(getUsername());
        sysLogistics.setState("已发货");
        return toAjax(sysLogisticsService.insertSysLogistics(sysLogistics));
    }

    /**
     * 修改物流配送
     */
    @Anonymous

    @Log(title = "物流配送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLogistics sysLogistics)
    {
        return toAjax(sysLogisticsService.updateSysLogistics(sysLogistics));
    }

    /**
     * 删除物流配送
     */
    @Anonymous

    @Log(title = "物流配送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysLogisticsService.deleteSysLogisticsByIds(ids));
    }
}
